//import and clean IPCC scenario data

import excel using "../Raw/Scenarios IPCC/data_selected_scenarios.xlsx",  clear firstrow
drop if Model == ""

replace Variable = "total_co2_Mt_CO2yr" if Variable == "AR6 climate diagnostics|Infilled|Emissions|CO2"
replace Variable = "kyoto_gases_Mt_CO2eyr" if Variable == "AR6 climate diagnostics|Infilled|Emissions|Kyoto Gases (AR5-GWP100)"
replace Variable = "coal_power_capacity_GW" if Variable == "Capacity|Electricity|Coal"
replace Variable = "primaryenergy_coal_EJyr" if Variable == "Primary Energy|Coal"
replace Variable = "secondaryenergy_elec_coal_EJyr" if Variable == "Secondary Energy|Electricity|Coal"
drop if Variable == "Emissions|CO2"
drop Unit DH

ds Model Scenario Region Variable, not
local torename `r(varlist)'
foreach v of local torename {
	destring `v', replace
    local lbl : variable label `v'
    rename `v' y_`lbl' 
}


reshape long y_, i(Model Scenario Region Variable) j(year)
rename y_ y
reshape wide y, i(Model Scenario Region year) j(Variable) string
rename year tyear 
rename y* * 
rename tyear year

//fill in with interpolation
foreach var of var coal_power_capacity_GW kyoto_gases_Mt_CO2eyr primaryenergy_coal_EJyr secondaryenergy_elec_coal_EJyr total_co2_Mt_CO2yr {
	//tempname vi 
	tempvar vi
	by Model Scenario Region: ipolate `var' year, gen(`vi')
	replace `var' = `vi' if missing(`var')
	drop `vi'
}

compress
save ../Intermediate/ipcc_scenarios_data, replace
